package com.ourhealth.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.ourhealth.entity.Result;
import com.ourhealth.service.ReportService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("report")
public class ReportController {
    @Reference
    private ReportService reportService;

    @RequestMapping("getMemberReport")
    public Result getMemberReport(){
        Map map = reportService.report(new Date());
        return new Result(true,"",map);
    }

    @RequestMapping("getSetmealReport")
    public Result getSetmealReport(){
        Map map = reportService.getSetmealReport();
        return new Result(true,"",map);
    }

    @RequestMapping("getBusinessReportData")
    public Result getBusinessReportData(){
        Map map = reportService.getBusinessReportData();
        return new Result(true,"",map);
    }

    @RequestMapping("getMemberReportByDate")
    public Result getMemberReportByDate(@RequestBody String[] dates){

        if (dates[0].equals("load")){
            getMemberReport();
        }

        DateTime dateBegin = DateUtil.parseDate(dates[0]);
        DateTime dateB = DateUtil.offsetDay(dateBegin, 1);
        DateTime dateEnd = DateUtil.parseDate(dates[1]);
        DateTime dateE = DateUtil.offsetDay(dateEnd, 1);

        String dateBeginString = dateB.toString("yyyy-MM-dd");
        String dateEndString = dateE.toString("yyyy-MM-dd");

        System.out.println(dateBegin);
        System.out.println(dateEnd);

        Map map = reportService.getMemberReportByDate(dateBeginString,dateEndString);

        return new Result(true,"",map);
    }

    /**查询男女性别和年龄段占比
     * @return
     */
    @RequestMapping("/getSexReport")
    public Result getSexReport(){
      Map<String, Object> map= reportService.getSexReport();
       return Result.success("",map);
    }
}
